//
//  CheckBoxView.m
//  CheckBoxDemo
//
//  Created by liuchang on 15/1/10.
//  Copyright (c) 2015年 liuchang. All rights reserved.
//

#import "CheckBoxView.h"

@implementation CheckBoxView

- (instancetype)initWithFrame:(CGRect)frame
                      IsCheck:(BOOL)isCheck
{
    self = [super initWithFrame:frame];
    if (self) {
        self.isCheck = isCheck;
        
        self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 48.0f, 48.0f)];
        if (isCheck) {
            [_imageView setImage:[UIImage imageNamed:@"cb_box_on.png"]];
        }
        else {
            [_imageView setImage:[UIImage imageNamed:@"cb_box_off.png"]];
        }
        [self addSubview:_imageView];
        
        UIButton * button = [UIButton buttonWithType:UIButtonTypeSystem];
        [button setFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        [button setBackgroundColor:[UIColor clearColor]];
        [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:button];
    }
    return self;
}

- (void)buttonAction:(id)sender
{
    _isCheck = !_isCheck;
    if (_isCheck) {
        [_imageView setImage:[UIImage imageNamed:@"button_check_effect"]];
    }
    else {
        [_imageView setImage:[UIImage imageNamed:@"button_check"]];
    }
}

@end
